#include "jdv.hh"

static std::string
stringify (int x)
{
  std::ostringstream o;

  o << x;
  return o.str ();
}

static
std::string
print_num (int n)
{
  std::string s;
  s = stringify (n);

  if (n <= 0)
    s = "  ";
  else if (n < 10)
    s = '0' + s;
  else if (n > 99)
    s = s.substr (s.size () - 2);
  return s;
}

void
Jdv::print ()
{
  int i = 0;
  int j = 0;

  for (i = -1; i < map_->get_h (); ++i)
  {
    std::cout << print_num (i + 1) << "|";
    //
    // Print cases
    //
    for (j = 0; j < map_->get_w (); ++j)
    {
      if (i == -1 && j != map_->get_w () - 1)
	std::cout << print_num (j + 1) << " ";
      else if (i == -1 && j == map_->get_w () - 1)
	std::cout << print_num (j + 1) << "|";
      else if (i != -1)
      {
	map_->print_ant (j, i);
	std::cout << "|";
      }
    }
    //
    // print interlignes
    //
    std::cout << std::endl;
    for (j = -1; j < map_->get_w (); ++j)
      if (j == -1 && i != -1 && i != map_->get_h () - 1)
	std::cout << "  -";
      else
	std::cout << "---";
    std::cout << std::endl;
  }
}
